var mongoose = require('mongoose');
var dateformat = require('dateformat');
var Schema = mongoose.Schema;
var _ = require("underscore");

//定义model的规范
var goodsSchema = new Schema({//荣誉商品数据
    goods_id: String,//商品ID
    goods_name: String, //商品名称
    goods_price: Number,//商品价格，单位：分
    category_id: String,//商品目录ID
    category_name: String,//商品目录名称
    pic_url: String,//商品图片
    count: Number,//购买数量
    note: String,//商品备注
    fee: Number//合计价格
});
var orderSchema = new Schema({
    trade_no: String,//订单编号
    total_fee: Number,//订单总价，单位：分
    user_openid: String,//客户id
    user_nickname: String,//客户昵称
    pass_code: String,//获取密码
    create_date: Date, //创建日期
    create_ip: String,//创建IP
    summary: String,//订单概要
    system_user_id: String,//系统用户ID
    goodses: [goodsSchema]//商品列表
});

orderSchema.virtual('create_date_format').get(function () {
    return dateformat(this.create_date, 'yyyy/mm/dd HH:MM:ss');
});
orderSchema.virtual('total_fee_format').get(function () {
    return this.total_fee / 100;
});


//注册model
mongoose.model("CafeOrder", orderSchema);

//获得Model
var CafeOrder = mongoose.model("CafeOrder");

module.exports = CafeOrder;